<?php
session_start();
if (!isset($_SESSION['admin']))
    header('location:index.php');
?>

<!DOCTYPE HTML>
<html>

    <head>
        <title>3D|didongde 3D- Di động đây</title>
        <?php include('modules/page_head.php'); ?>
    </head>

    <body>
        <div id="main">
            <div id="header">
                <div id="logo">
                    <h1><a href="index.php">Didongde</a></h1>
                    <div class="slogan">Where you can find your own best suitable mobile</div>
                    <?php include('modules/logo_header.php'); ?>
                </div>
                <div id="menubar">
                    <?php include('modules/menubar.php'); ?>
                </div>
            </div>
            <div id="site_content">
                <div id="sidebar_container">
                    <h2>Tìm kiếm nhanh</h2>
                    <div class="sidebar">
                        <?php
                        include ("modules/quick_search.php");
                        show_manu();
                        ?>
                    </div>
                    <div class="sidebar">
                        <?php show_price(); ?>
                    </div>
                </div>
                <div id="content">
                    <!-- insert the page content here -->
                    <h2>Duyệt các sản phẩm trong kho</h2>
                    <?php
                    /* connect to database server */
                    include_once('conf/dbconfig.php');
                    $cfg = new dbconfig();
                    $host = $cfg->get_dbhost();
                    $db = $cfg->get_dbname();
                    $usr = $cfg->get_dbusername();
                    $pass = $cfg->get_dbpwd();
                    $connection = pg_connect("host = $host dbname = $db user = $usr password = $pass")
                            or die("Cannot connect to database server");

                    $query = "select * from mobilephone";
                    $result = pg_query($connection, $query);
                    echo "<table>";
                    echo "<tr><th>STT</th><th>Model</th><th>Số lượng trong kho</th></tr>";
                    for ($i = 1; $i <= pg_num_rows($result); $i++) {
                        $model = pg_fetch_result($result, $i - 1, 'model');
                        echo "<tr><td>$i</td><td>" . $model . "</td><td style=\"text-align:center;\">";
                        echo pg_fetch_result($result, $i - 1, 'quantity') . "</td><td>";
                        echo "<a href=\"admin_change_mobilephone.php?model=$model\" >Sửa thông tin</a></td><td>";
                        echo "<a title=\"Xóa điện thoại này\" href=\"admin_del_mobilephone.php?model=$model\" class=\"xoa\"></a></td></tr>";
                    }
                    echo "</table>";
                    ?>
                </div>
            </div>
        </div>
        <div id="footer">
            <?php include('modules/footer.php'); ?>
        </div>
    </body>
</html>
